package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/10/19 11:33
 */
@Component
@Slf4j
public class SsmSendListener {
    @Autowired
    private FilterChainManager filterChainManager;
//    监听 接口模块发送消息到策略模块队列
    @RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
    public void messageHandler(Channel channel, Message message, StandardSubmit standardSubmit) throws Exception {
        log.info("[策略模式]接收到短信对象,standardSubmit={}",standardSubmit);
//        调用责任链管理者接口,来实现各种策略执行
        filterChainManager.executeFilter(standardSubmit);


//        rabbittMQ手动确认接收到短信对象
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }

}
